<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta charset="utf-8"/>
    <title>用户登录</title>
    <link rel="icon" href="/assets/images/favicon.ico">
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/assets/css/login.css" media="all">
</head>
<body>
<div class="login-wrapper">
    <div class=" login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户登录
            </div>
            <div class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="username" type="text" lay-verify="required" placeholder="账号"
                               value="admin" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input name="password" type="password" lay-verify="required" placeholder="密码"
                               value="123" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                    <div class="layui-input-block">
                        <input name="signal" type="text" lay-verify="required" placeholder="请输入登录暗号"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                    <div class="layui-input-block">
                        <div class="layui-row inline-block">
                            <div class="layui-col-xs7">
                                <input name="code" type="text" lay-verify="required" placeholder="验证码"
                                       minlength="4" maxlength="4" class="layui-input">
                            </div>
                            <div class="layui-col-xs5" style="padding-left: 10px;">
                                <img class="login-captcha">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <!--
                    <a href="javascript:;" class="layui-link">帐号注册</a>
                    <a href="javascript:;" class="layui-link pull-right">忘记密码？</a>
                    -->
                    <a id="signal" href="javascript:;" class="layui-link pull-right">点击获取登录暗号</a>
                </div>
                <div class="layui-form-item">
                    <button lay-filter="login-submit" class="layui-btn layui-btn-normal layui-btn-fluid" lay-submit>登 录</button>
                </div>
                <div class="layui-form-item login-other">
                    <label>第三方登录</label>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>
                </div>
            </div>
        </div>
    </div>
    <div class="login-footer">
        <p>© 2018 <a href="http://crab.baomidou.com" target="_blank">Crab 版权所有(盗版必究)</a></p>
    </div>
</div>
<script type="text/javascript" src="/assets/libs/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/assets/libs/layui/layui.js"></script>
<script>
    layui.config({
        base: 'module/'
    }).use(['config', 'form', 'crab'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var config = layui.config;
        var crab = layui.crab;

        console.log('--crab.getUser()---', crab.getUser())
        if (crab.getUser()) {
            location.replace('./');
            return;
        }

        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            crab.post('/sso/login', obj.field, function (data) {
                crab.putUser(data);
                layer.msg('登录成功', {icon: 1}, function () {
                    location.replace('./');
                });
            });
        });

        $('#signal').click(function () {
            crab.popupCenter({
                title: '关注微信公众号，发送 \' 暗号 \' 二字获取暗号内容',
                path: '/signal.html'
            });
        });

        // 图形验证码
        var captcha = $('.login-captcha');
        captcha.attr('src', config.base_server + '/draw/captcha/image');
        captcha.click(function () {
            this.src = this.src + '?t=' + (new Date).getTime();
        });
    });
</script>
</body>
</html>